<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>【案例】显示隐藏密码明文</title>
    <script>
    </script>
</head>
<body>
    <div class="box">
        <lable for="">
            <img src = "images/close.png" alt="" id="eye">
        </lable>
        <input type="password" name="" id="pwd">
    </div>
    <script>
        //1.获取元素
        var eye = document.getElementById('eye');
        var pwd = document.getElementById('pwd');
        //2.注册事件处理程序
        var flag = 0;
        eye.onclick = function (){
            //每次单机，修改flag的值
            if(flag === 0 ){
                pwd.type = 'text';
                eye.src = 'images/open.png';
                flag = 1;
            } else{
                pwd.type = 'password';
                eye.src = 'images/close.png';
                flag = 0;
            }
        };

    </script>
</body>
</html>